package com.zjhd.sealcutting.service.impl;

import com.zjhd.sealcutting.dao.WorksCommentMapper;
import com.zjhd.sealcutting.domain.WorksComment;
import com.zjhd.sealcutting.service.WorksCommentService;
import com.zjhd.sealcutting.utils.DateUtil;
import com.zjhd.sealcutting.utils.response.ResponseResult;
import com.zjhd.sealcutting.utils.response.ResultGenerator;
import com.zjhd.sealcutting.vo.WorksCommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * TODO  作品评论
 *
 * @author wangchao
 * @version 1.0
 * @date 2020/12/3 15:42
 */
@Service
public class WorksCommentServiceImpl implements WorksCommentService {

    @Autowired
    private WorksCommentMapper worksCommentMapper;


    /**
     * TODO 新增作品评论
     * @author wangchao
     * @date 2020/12/3 15:44
     * @param
     * @return
     */
    @Override
    @Transactional
    public ResponseResult insertWorksComment(WorksComment worksComment) throws Exception {
        try {
            worksComment.setCommentTime(DateUtil.getCurrentTime());
            int i=worksCommentMapper.insert(worksComment);
            if(i>0){
                return ResultGenerator.genSuccessResult("新增作品评论成功!");
            }else {
                return ResultGenerator.genFailResult("新增作品评论失败!");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultGenerator.genFailResult("新增作品评论失败!");
    }

    /**
     * TODO 根据作品ID查询作品评论
     * @author wangchao
     * @date 2020/12/3 16:28
     * @param
     * @return
     */
    @Override
    public List<WorksCommentVo> queryByWorkIdComment(String workId) throws Exception {
        return worksCommentMapper.queryByWorkIdComment(workId);
    }
}
